from django import forms
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.contrib.auth.forms import AuthenticationForm

class AuthorizationPageForm(AuthenticationForm):

    username = forms.CharField(
        widget=forms.TextInput(attrs={
            "type": "text", "id": "user", "name": "user", "placeholder": "username"}))
           
    password = forms.CharField(widget=forms.PasswordInput(attrs={
        "type": "password", "id": "pass", "name": "pass", "placeholder": "password"}))

    class Meta:

        model = User
        fields = ['username', 'password']


#class AuthorizationPageForm(forms.Form):
#
#    username = forms.CharField(
#        widget=forms.TextInput(attrs={
#            "type": "text", "id": "user", "name": "user", "placeholder": "username"}))
#           
#    password = forms.CharField(widget=forms.PasswordInput(attrs={
#        "type": "password", "id": "pass", "name": "pass", "placeholder": "dfskjsfdjpassword"}))
#
#
#    def clean_username(self):
#
#        list_of_users = User.objects.values_list('username', flat=True)
#        specified_name = self.cleaned_data['username']
#
#        if not specified_name in list_of_users: 
#            print('Пользователя не существует')
#            raise ValidationError('There is no such user')
#
#        return specified_name
